/***
 * 时间处理工具
 */
export default{
    dateToStr(date) {
      if(date==null)date=new Date();
      else date=new Date(date);
      var year = date.getFullYear();//年
      var month = date.getMonth()+1;//月
      var day = date.getDate();//日
      var hours = date.getHours();//时
      var min = date.getMinutes();//分
      var second = date.getSeconds();//秒
      return year + "-" +
        (month  > 9 ? month  : ("0" + month)) + "-" +
        (day > 9 ? day : ("0" + day)) + " " +
        (hours > 9 ? hours : ("0" + hours)) + ":" +
        (min > 9 ? min : ("0" + min)) + ":" +
        (second > 9 ? second : ("0" + second));
    },
    now(){
        return this.dateToStr(new Date());
    },
    parse(str){
        return new Date(str);
    },
    addMonth(date,n){
        if(date==null)date=new Date();
        var d1=this.clone(date);
        d1.setMonth(d1.getMonth()+n);       
        return d1;
    },
    addDay(date,n){
        if(date==null)date=new Date();
        var d1=this.clone(date);
        d1.setDate(d1.getDate()+n);
        return d1;
    }
    ,
    addHour(date,n){
        if(date==null)date=new Date();
        var d1=this.clone(date);
        d1.setHours(d1.getHours()+n);
        return d1;
    },
    clone(d)
    {
        //var s=this.dateToStr(d);
        //console.log(s)
        var d1= new Date(d);
        //console.log(d1);
        return d1;
    },
    getTimeInterval(time1, time2) {
        // 将时间字符串转换为Date对象
        var date1 = new Date(time1);
        var date2 = new Date(time2);
     
        // 计算时间间隔（毫秒）
        var interval = date2.getTime() - date1.getTime();

        return interval;
    },
    getTimeHourInterval(time1, time2){
        var interval = this.getTimeInterval(time1,time2);
        return interval/(60*60*1000);
    },
    getTimeMinuteInterval(time1,time2){
        var interval = this.getTimeInterval(time1,time2);
        return interval/(60*1000);
    }


}